home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE04 / CLIPFIX / CLIPFIX.PAS
Encoding:
Pascal/Delphi Source File  |  1995-10-04  |  1.7 KB  |  50 lines

  1. { Fixes to Custom Clipboard Formats article from Issue 3 }
  2. { See Xavier Pacheco's note on page 51 of this issue     }
  3.  
  4. { PasteFromClipboard OLD version }
  5. procedure TBirthday.PasteFromClipBoard;
  6. var
  7.   Data: THandle;
  8.   DataPtr: Pointer;
  9.   C: Char;
  10.   Size: Integer;
  11. begin
  12.   Data := ClipBoard.GetAsHandle(CF_BIRTHDAY);   { Get the data on the clipboard }
  13.   try
  14.     if Data = 0 then Exit;                      { Exit is unsuccessful }
  15.     DataPtr := GlobalLock(Data);                { Lock the Global memory object }
  16.     try
  17.       if SizeOf(FPersonRec) > GlobalSize(Data) then Size := GlobalSize(Data);
  18.         { Copy contents of DataPtr to Buffer }
  19.       Move(DataPtr^, FPersonRec, SizeOf(FPersonRec));
  20.     finally
  21.       GlobalUnlock(Data);          { Unlock the global memory object }
  22.     end;
  23.   except
  24.     GlobalFree(Data);              { Free the memory allocated, only if    }
  25.     raise;                         { an exception occurs as this memory is }
  26.   end;                             { managed by the Windows }
  27. end;
  28.  
  29. { NEW fixed version (Listing 1 in Xavier's note on the fix) }
  30. procedure TBirthday.PasteFromClipBoard;
  31. var
  32.   Data: THandle;
  33.   DataPtr: Pointer;
  34.   Size: Integer;
  35. begin
  36.   Data := ClipBoard.GetAsHandle(CF_BIRTHDAY); { Get the data on the clipboard }
  37.   if Data = 0 then Exit;                    { Exit is unsuccessful }
  38.   DataPtr := GlobalLock(Data);              { Lock the Global memory object }
  39.   try
  40.     if SizeOf(FPersonRec) > GlobalSize(Data) then
  41.        Size := GlobalSize(Data)
  42.     else
  43.        Size := SizeOf(FPersonRec);
  44.       { Copy contents of DataPtr to Buffer }
  45.     Move(DataPtr^, FPersonRec, Size);
  46.   finally
  47.     GlobalUnlock(Data);   { Unlock the global memory object }
  48.   end;
  49. end;
  50.